package com.violet.db.config;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 类说明: mybatis-plus 批量此操作自定义接口
 *
 * @author wqf
 * @date 2022/9/27 15:03
 */
@Slf4j
public class BatchSqlInjector extends DefaultSqlInjector {

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        if (mapperClass == null) {
            log.warn("没有数据需要插入===");
            return Collections.emptyList();
        }
        List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
        if (methodList.isEmpty()) {
            log.warn("没有数据需要插入===");
            return Collections.emptyList();
        }
        // 添加InsertBatchSomeColumn方法
        methodList.add(new InsertBatchSomeColumn());
        return methodList;
    }


}